//
// Created by nicemoe on 2021/8/8.
//

#include  <bits/stdc++.h>
using namespace std;

int main() {
    priority_queue<int,vector<int>,greater<> > pq;
    int n,x,y;
    cin >> n;
    while(n--) {
        cin >> x;
        if(x==1){
            cin >>y;
            pq.push(y);
        } else if (x==2){
            cout << pq.top() << endl;
        } else{
            pq.pop();
        }
    }
    return 0;
}
